package com.xbongbong.crm.handle.analysis;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainDTO;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.base.CommunicateBaseEnum;
import com.xbongbong.saas.toolbox.help.FastJsonHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Objects;

import static com.xbongbong.saas.toolbox.help.FastJsonHelper.getIntegerOrDefaultFromFormData;

/**
 * @author sunshaoxiang
 * @ClassName CustomerCommunicateDetailAnalysisDataHandler
 * @Description 访客计划数据解析
 * @Date 2022/6/7 15:02
 * @Version 1.0
 **/
@Component
public class CustomerCommunicateDetailAnalysisDataHandler {

    public static final Logger LOGGER = LoggerFactory.getLogger(CustomerCommunicateDetailAnalysisDataHandler.class);

    public void handleDetailSpecialField(JSONObject data, Long dataId, Integer businessType, String corpid, Map<String, FieldAttrEntity> explainMap, Long formId, HandlerExplainDTO handlerExplainDTO) throws XbbException {
        Integer crmBusinessType = getIntegerOrDefaultFromFormData(data, CommunicateBaseEnum.COMMUNICATE_BUSINESS_TYPE.getAttr(), BasicConstant.ZERO);
        if (!Objects.equals(crmBusinessType, BasicConstant.ZERO)) {
            String businessName = FastJsonHelper.getStringOrDefaultFromFormData(data, CommunicateBaseEnum.COMMUNICATE_BUSINESS_HIDE.getAttr(), "");
            if (!businessName.isEmpty()) {
                businessName = RedundantTemplateTypeEnum.getByCode(crmBusinessType).getName() + PaasConstant.LEFT_BRACKET + businessName + PaasConstant.RIGHT_BRACKET;
                data.put(CommunicateBaseEnum.COMMUNICATE_BUSINESS_HIDE.getAttr(), businessName);

            }
        }
    }
}
